//
//  CYPayWayBtn.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/7.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYPayWayBtn.h"
@interface CYPayWayBtn()
/*选中状态，显示的图片*/
@property (nonatomic, strong) CYImageView *selectIMG;
/*按钮的图片*/
@property (nonatomic, strong) CYImageView *mainIMG;
/*按钮的名字*/
@property (nonatomic, strong) CYLabel *titleLBL;
/*下划线*/
@property (nonatomic, strong) CYView *line;

@property (nonatomic, copy) NSString *imageName;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, assign) CGFloat fontzise;
@property (nonatomic, strong) UIColor *color;
@end
@implementation CYPayWayBtn
- (instancetype)initWithTitle:(NSString *)title titleColor:(UIColor *)color titleSize:(CGFloat)size Image:(NSString *)image{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _title = title;
        _imageName = image;
        _fontzise = size;
        _color = color;
        self.selectIMG.hidden = self.mainIMG.hidden = self.titleLBL.hidden = self.line.hidden = NO;
        
    }
    return self;
}

- (CYImageView *)selectIMG{
    if (!_selectIMG) {
       _selectIMG = [[CYImageView alloc]initWithImageName:@"unselect" size:CGSizeMake(AL(PT(35)), AL(PT(35))) isRadius:YES];
        [self addSubview:_selectIMG];
        
        WS(self)
        [_selectIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mas_right).with.offset(0);
            make.centerY.equalTo(weakSelf);
            make.size.mas_equalTo(_selectIMG.bounds.size);
        }];
        
    }
    return _selectIMG;
}

- (CYImageView *)mainIMG{
    if (!_mainIMG) {
      _mainIMG = [[CYImageView alloc]initWithImage:[UIImage imageNamed:_imageName]];
        [self addSubview:_mainIMG];
        
        WS(self)
        [_mainIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf).with.offset(0);
            make.centerY.equalTo(weakSelf);
            make.size.mas_equalTo(CGSizeMake(AL(PT(38)), AL(PT(38))));
        }];
    }
    return _mainIMG;
}

- (CYLabel *)titleLBL{
    if (!_titleLBL) {
       _titleLBL = [[CYLabel alloc]initWithText:_title size:_fontzise textcolor:_color];
        [self addSubview:_titleLBL];
        
        WS(self)
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_mainIMG.mas_right).with.offset(AL(PT(24)));
            make.centerY.equalTo(weakSelf);
            make.size.mas_equalTo(_titleLBL.bounds.size);
        }];
    }
    return _titleLBL;
}

- (CYView *)line{
    if (!_line) {
        _line = [[CYView alloc]initWithColor:ColorHex(0xf2f2f2)];
        [self addSubview:_line];
        
        WS(self)
        [_line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(weakSelf.mas_bottom).with.offset(0);
            make.right.equalTo(weakSelf.mas_right).with.offset(0);
            make.left.equalTo(weakSelf).with.offset(0);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _line;
}

- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    _selectIMG.image = (selected)?[UIImage imageNamed:@"selected"]:[UIImage imageNamed:@"unselect"];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
